package org.nf.material.service.impl;

import org.nf.material.dao.MaterialDAO;
import org.nf.material.dao.impl.MaterialDaoImpl;
import org.nf.material.model.Material;
import org.nf.material.service.MaterialService;
import org.nf.product.dao.ProductDAO;
import org.nf.product.dao.impl.ProductDaoImpl;
import org.nf.product.util.PageUtils;
import org.nf.product.vo.PageVO;

import java.util.List;

public class MaterialServiceImpl implements MaterialService {
    private MaterialDAO materialDAO = new MaterialDaoImpl();
    @Override
    public int insert(Material material) {
        return materialDAO.insertMaterial(material);
    }

    @Override
    public List<Material> selectMaterialName(String materialName) {
        return materialDAO.selectMaterialName(materialName);
    }

    @Override
    public List<Material> listMaterial(Material material) {
        return materialDAO.listMaterial(material);
    }

    @Override
    public PageVO<List<Material>> listMaterialPage(int page, int limit) {
        Material material = new Material();
        //先根据page计算出从表的第几条开始查询
        int numberOf = PageUtils.toNumberOf(page, limit);
        //创建DAO实例
        MaterialDAO dao = new MaterialDaoImpl();
        List<Material> list =dao.listMaterialPage(material,page,limit);
        Long count=dao.countMaterial();
        //将数据封装成PageVO对象并返回
        return PageUtils.toPageVO(list,count);
    }
}
